home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11514 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  56 lines

  1. Path: news.vanderbilt.edu!news
  2. From: haseltbt@ctrvax.vanderbilt.edu (Bennett Haselton)
  3. Newsgroups: comp.lang.c++
  4. Subject: works in Borland but not in Microsuck Visual C++
  5. Date: 14 Mar 1996 22:27:52 GMT
  6. Organization: Vanderbilt University
  7. Message-ID: <4ia6h8$jes@news.vanderbilt.edu>
  8. NNTP-Posting-Host: dial117.vanderbilt.edu
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=ISO-8859-1
  11. X-Newsreader: WinVN 0.99.5
  12.  
  13.     Dear Abby,
  14.  
  15.         The following program was written in completely standard C++ 
  16. and should be portable across platforms.  However, it only performs as 
  17. expected (i.e. sends two copies of 4 to the standard out stream) in Borland 
  18. C++; when compiled in MicroSUCK Visual C++, it outputs 4 followed by a random 
  19. integer in the thousands.
  20.  
  21. #include <iostream.h>
  22.  
  23. struct person {
  24.     int age;
  25. };
  26.  
  27. struct person* matchPerson( struct person* psnPtr )
  28. {
  29.     struct person* ansPtr;
  30.     ansPtr->age = psnPtr->age;
  31.     cout << ansPtr->age;
  32.     cout << ansPtr->age;
  33.     return ansPtr;                         
  34. };
  35.  
  36. void main()
  37. {
  38.     struct person myperson;
  39.     myperson.age = 4;
  40.     struct person* k = matchPerson( &myperson );
  41. }
  42.  
  43. i was using version 1.0 of Visual C++; i have no knowledge of whether later 
  44. Microsuck compilers are capable of handling a program like this properly.  
  45. Please avoid buying their products whenever possible if you have not already 
  46. resolved to do so.
  47.     Is there a further explanation of this anomaly which i did not come 
  48. across?  As usual, great Microsuck jokes will be mailed to anyone who can 
  49. help.  Thanks!
  50.  
  51.     Love,
  52.  
  53.         tm
  54.     -bennett
  55.  
  56.